/*
TODO:
==========================================================================================
#1: paralelizace podle paralelni prace s polem v projektu CUDA
    - pouze zkopirovat data na GPU
    - paralelne zkomprimovat bloky
    - vytahnout z GPU a ulozit do souboru
#2: optimalizace
    - pristup do pameti
    - asynchronni kopirovani na GPU a pousteni kernelu vzhledem k nacitani souboru na CPU
    - a dalsi zminene v mych poznamkach
#4: profilace? jak moc casu zabira MergeSort? predpokladany bottleneck...paralelni sort?
#5: profilace, mereni casu vypoctu, mereni transferu dat
#6: zaverecna zprava
==========================================================================================

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;

#include "CudaWorker.h"

int main()
{
    srand(time(NULL));
    const int arrSize = 10;
    int arr[arrSize];
    for(int i = 0; i < arrSize; i++)
        arr[i] = rand();
    //
    cout << "Before:";
    for(int i = 0; i < arrSize; i++)
        cout << ' ' << arr[i];
    //
    CudaWorker cuda;
    cuda.doCuda(arrSize, arr);
    //
    cout << "\nAfter:";
    for(int i = 0; i < arrSize; i++)
        cout << ' ' << arr[i];
    //
    cout << endl;
    return 0;
}
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#include "../config.h"
#include "CudaWorker.h"

int main(int argc, char **argv)
{
   if(argc != 3)
    {
        cout << "Usage: ./prc_seq file_to_compress.any       compressed_file.any.prc\n"
             << " or    ./prc_seq file_to_decompress.any.prc decompressed_file.any" << endl;
        return 1;
    }
    ifstream fin(argv[1], ios_base::in | ios_base::binary);
    if(!fin.is_open()) { cerr << "File reading error!" << endl; return 1; }
    ofstream fout(/*argv[2]*/"step1.mn5", ios_base::out | ios_base::binary);
    if(!fout.is_open()) { cerr << "File writing error!" << endl; return 1; }
    // compression or decompression??
    bool decompress = false;
    if(strcmp(argv[1] + strlen(argv[1]) - 4, ".prc") == 0)
        decompress = true;
    //
    // Compression / Decompression
    CudaWorker worker;
    if(decompress)
        worker.doCudaCompression(fin, fout);
    else
        worker.doCudaCompression(fin, fout);
    //
    fout.close();
    fin.close();
    //
    return 0;
}